<template>
  <div class="personal">
    <router-link :to="'/edit_profile/'+ userinfo.id">
      <div class="profile">
        <!-- $axios.defaults.baseURL读取axios的服务器路径 -->
        <img :src="userinfo.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span class="iconfont iconxingbienan"></span>{{userinfo.nickname}}
          </div>
          <div class="time">{{userinfo.create_date | dateFormat}}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell title='我的关注' desc='关注的用户' @click="$router.push({name:'myfollow'})"></mycell>
    <mycell title='我的跟帖' desc='跟帖/回复'></mycell>
    <mycell title='我的收藏' desc='文章/视频' @click="$router.push({name: 'mystar'})"></mycell>
    <mycell title='设置'></mycell>
    <mybutton type='waring' @click="editApp">退出</mybutton>
  </div>
</template>

<script>
import mycell from '@/components/mycell.vue'
import mybutton from "@/components/mybutton.vue";
import {getUserInfo} from '@/apis/user.js'
import axios from '@/utils/myaxios.js'
import {dateFormat} from '@/utils/myfilter.js'
export default {
  data () {
    return {
      userinfo:{}
    }
  },
  components:{
    mycell,mybutton
  },
  // 由于封装的是函数，所以得进行注册，确定它是用于过滤器
  filters: {
    dateFormat
  },
  methods: {
    editApp(){
      localStorage.removeItem('hm_toutiao')
      this.$router.push({path:'/index'})
    },
  },
  async mounted () {
    let id = this.$route.params.id
    let res = await getUserInfo(id)
    console.log(res)
    this.userinfo = res.data.data
    if (this.userinfo.head_img){
      this.userinfo.head_img = axios.defaults.baseURL + this.userinfo.head_img
    }else{
      this.userinfo.head_img = axios.defaults.baseURL + '/uploads/image/default.jpeg'
    }
  }
};
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}

.btn {
  margin:  20px auto;
  background-color: #f00;
}
</style>